<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>过滤记账记录</title>
<link rel="stylesheet" href="./css/left-nav.css">
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/record.css">
<style type="text/css">
    .tableInfo{
    	margin-left: 500px;
    }
</style>
</head>
<body>
<!-- 左侧导航 -->
    <div class="left_nav" id="nav_left">
        <div class="head clearfix">
            <div class="head_icon"></div>
            <div class="head_word"><a href="home.jsp">返回首页</a></div>
        </div>
        <ul>
            <li>
                <span class="second_icon"></span>
               筛选账单
            </li>
            
        </ul>
    </div>
<%
	String filterNum = request.getParameter("filterNum");
	String amount = request.getParameter("amount");
	int filterNums = Integer.parseInt(filterNum);
	
	String url = "jdbc:mysql://localhost:3306/wacai?serverTimezone=Asia/Shanghai";
	Connection connection = null;
	Statement stmt = null;
	String sql = null;
	
	if(filterNum!=null){
		try{
			Class.forName("com.mysql.jdbc.Driver");
		}catch(ClassNotFoundException exception){
			out.println("加载驱动器类时出现异常");
		}
		
		try{
			connection = DriverManager.getConnection(url,"root","root1234");//连接数据库
			sql = "select * from record";
			stmt = connection.createStatement();
			ResultSet resultSet = stmt.executeQuery(sql);
			
			%>
			<div class="right">
			<table width="740" border="1" cellpadding="6" cellspacing="0" class="tableInfo">
			<caption>金额大于<%=filterNums %>元的账单筛选</caption>
			<tr class="tr1">
				<td width="100" height="30" align="center" valign="middle">记账时间</td>
				<td width="145" align="center" valign="middle">记账金额</td>
				<td width="145" align="center" valign="middle">收支</td>
				<td width="148" align="center" valign="middle">资金类型</td>
			</tr>
		
	<%
		while(resultSet.next()){
			int moneyNum = resultSet.getInt(2);
			if(moneyNum>filterNums){
				String createTime = resultSet.getString(1);
				String select1 = resultSet.getString(3);
				String select2 = resultSet.getString(4);
			%>
				<tr class="tr2">
					<td height="40" align="center" valign="middle"><%=createTime %></td>
					<td align="center" valign="middle"><%=moneyNum %></td>
					<td align="center" valign="middle"><%=select1 %></td>
					<td align="center" valign="middle"><%=select2 %></td>
				</tr>
			<%
		}}
		
	%>
		</table>	
		</div>	
	<%	
		resultSet.close();
		stmt.close();
		}catch(Exception e){
			out.print("<script type='text/javascript'>alert('筛选账单失败');</script>");
			response.setHeader("Refresh","0.1;url=home.jsp");
		}}
	%>
</body>
</html>